const svgCaptcha = require('svg-captcha')
const { setValue } = require('../config/redisConfig')

class PublicController {
  async getCaptcha(ctx) {
    const { sid } = ctx.request.query
    console.log(sid)
    const newCaptcha = svgCaptcha.create({
      size: 4,
      ignoreChars: '0o1il',
      color: true,
      noise: Math.floor(Math.random() * 4),
      width: 150,
      height: 38,
      fontSize: 36
    })
    // 保存图片验证码，设置超时时间，单位s
    setValue(sid, newCaptcha.text, 10 * 60)
    ctx.body = {
      code: 200,
      data: newCaptcha.data
    }
  }
}

module.exports = new PublicController()
